package com.dsjy.yf.address.component;

import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author whj
 * @version 1.0
 * @date 2021-02-02 17:28
 */
@Component
public class StringComparator implements Comparator<String> {

    @Override
    public int compare(String o1, String o2) {
        int num = o2.length() - o1.length();
        //判断字符串长度相同时，根据字典顺序排
        if (num == 0) {
            return o1.compareTo(o2);
        } else {
            return num;
        }
    }

}
